<script type="text/javascript" language="javascript">
    (function($) {
        /*whatever jQuery stuff*/
        $(function(){
			var DataAds = JSON.parse('<?php echo json_encode($dataJqplot);?>');
		  	var plot1 = $.jqplot('chart', DataAds, {
				title:'<strong>Avertisement Static</strong>',		
				axes:{
			  		xaxis:{
			  			renderer:$.jqplot.DateAxisRenderer,
			     		tickOptions:{
			      			formatString:'%b&nbsp;%#d'
			 			}
					}
				},
		  		highlighter: {
		    		show: false
				},
				cursor: {
					show: false
				}
		  	});				
			//SimpleDate Picker		
			$('.datetime').simpleDatepicker({ startdate: 1900, enddate: new Date().getFullYear() });	
        });
    })(jQuery);	
</script>
<div class="wrap">
 	<div id="icon-index" class="icon32"><br /></div><h2><?php echo ucwords(str_replace('_',' ',$this->uri->segment(1)));?> &raquo; <?php echo ucwords(str_replace('_',' ',$this->uri->segment(2)));?></h2>
</div>
<div id="wpbody-content">
    <div class="metabox-holder" id="dashboard-widgets">
            <div class="inside">
				<div id="filter_panel">
					<form action="<?php echo current_url();?>" method="get" name="SearchForm" id="SearchForm">
					<ul>
						<li>
							<span>Start Date :</span>
							<input type="text" name="start_date" id="start_date" class="medium-text datetime" value="<?php echo @$this->input->get('start_date');?>" readonly="readonly"/>
						</li>
						<li>
							<span>End Date :</span>
							<input type="text" name="end_date" id="end_date" class="medium-text datetime" value="<?php echo @$this->input->get('end_date');?>" readonly="readonly"/>
						</li>
						<li>
							<span>Ads Name :</span>
							<select name="ads_id" id="ads_id">
								<option value=""><?php echo lang('select_option');?></option>
								<?php $ads_arr = array();?>
								<?php if(!empty($dataResult)) foreach($dataResult as $value):?>
									<?php if(!in_array($value->ads_id,$ads_arr)):?>
										<option value="<?php echo $value->ads_id;?>" <?php echo (@$this->input->get('ads_id') == $value->ads_id ? 'selected="selected"':'');?>><?php echo $value->ads_name;?></option>
										<?php $ads_arr[] = $value->ads_id;?>
									<?php endif;?>
								<?php endforeach;?>
							</select>
						</li>																		
					</ul>
					<br />
					&nbsp;&nbsp;<input type="submit" value="<?php echo lang('button_search');?>" class="button-primary"/>
					<input type="reset" value="<?php echo lang('button_reset');?>" class="button-primary"/>
					</form>
				</div>
				<div class="tablenav top">
					<p class="search-box">
						<input type="button" onclick="javascript:toggleFilter(this);" class="button-primary" value="<?php echo lang('button_filter');?>" />
					</p>
				</div>
				<div id="chart"></div>
				<div class="wrap" style="width:99%;margin:10px 0;">
					<h2>Summary <a href="javascript:void(0);" class="tools report" onclick="$('#filter_summary').toggle()"></a></h2>
					<?php if(!empty($dataResult)):?>
						<?php $color_arr = array("#4bb2c5", "#EAA228", "#c5b47f", "#579575", "#839557", "#958c12","#953579", "#4b5de4", "#d8b83f", "#ff5800", "#0085cc");?>
						<?php $colorAt = 0;?>
						<?php $ads_arr = array();?>
						<ul id="filter_summary" style="display: none;border-bottom: 1px solid #868080;overflow: hidden;clear: both;">
							<li style="float:left;width:33%;background-color: #b6b3b1;"><strong>Name</strong></li>
							<li style="float:left;width:33%;background-color: #b6b3b1;"><strong>Impression</strong></li>
							<li style="float:left;width:34%;background-color: #b6b3b1;"><strong>Click</strong></li>
							<?php 
								foreach($dataResult as $value):
									if(!isset($ads_arr[$value->ads_id]['Impression'])) $ads_arr[$value->ads_id]['Impression'] = 0;
									if(!isset($ads_arr[$value->ads_id]['Click'])) $ads_arr[$value->ads_id]['Click'] = 0;
									$ads_arr[$value->ads_id]['ads_name'] = $value->ads_name;
									$ads_arr[$value->ads_id]['Impression'] += $value->Impression;
									$ads_arr[$value->ads_id]['Click'] += $value->Click;
								endforeach;
							?>
							<?php foreach($ads_arr as $value):?>
								<li style="float:left;width:33%;"><strong><font color="<?php echo $color_arr[$colorAt];?>"><?php echo $value['ads_name'];?></font></strong></li>
								<li style="float:left;width:33%;"><?php echo number_format($value['Impression']);?></li>
								<li style="float:left;width:34%;"><?php echo number_format($value['Click']);?></li>
								<?php $colorAt++;?>
							<?php endforeach;?>
						</ul>
					<?php endif;?>
				</div>	
				<form action="<?php echo current_url();?>/delete" method="post" name="ListForm" id="ListForm">
				<table cellspacing="0" class="wp-list-table widefat fixed">
					<thead>
					<tr>
						<?php 
							echo generate_th_orderby(array(
								array(
									'name' => lang('ads_id'),
									'width' => 60
								),
								array(
									'name' => lang('ads_name'),
								),
								array(
									'name' => lang('views'),
									'width' => 80
								),
								array(
									'name' => lang('click'),
									'width' => 80
								),
								array(
									'name' => lang('update_date')	
								)
							));
						?>
					</tr>
					</thead>
				
					<tfoot>
					<tr>
						<?php 
							echo generate_th_orderby(array(
								array(
									'name' => lang('ads_id'),
									'width' => 60
								),
								array(
									'name' => lang('ads_name'),
								),
								array(
									'name' => lang('views'),
									'width' => 80
								),
								array(
									'name' => lang('click'),
									'width' => 80
								),
								array(
									'name' => lang('update_date')	
								)
							));
						?>
					</tr>
					</tfoot>
				
					<tbody>
						<?php
						if(!empty($dataResult)):
							$ads_arr = array();
							$colorAt = 0;
							foreach($dataResult as $value):
								if(!array_key_exists($value->ads_id,$ads_arr)):
									$ads_arr[$value->ads_id] = $color_arr[$colorAt];
									$colorAt++;
								endif;
						?>
							<tr>
								<td class=""><?php echo sprintf('%06d',$value->ads_id);?></td>
								<td class=""><strong><font color="<?php echo $ads_arr[$value->ads_id];?>"><?php echo $value->ads_name;?></font></strong></td>
								<td class=""><?php echo $value->Impression;?></td>
								<td class=""><?php echo $value->Click;?></td>
								<td class=""><?php echo $value->date;?></td>
							</tr>
							<?php
							endforeach;
						else: //not exists
							?>
							<tr valign="middle" class="alternate"><td colspan="5"><?php echo lang('no_data');?></td></tr>			
						<?php
						endif;
						?>
					</tbody>
				</table>
				<div class="tablenav bottom"></div>				
				</form>
            </div><!-- wpbody inside -->
    </div><!-- wpcontent -->
</div><!-- wpbody-content -->